package com.opmsys.service.impl;

import com.opmsys.mapper.RecordMapper;
import com.opmsys.pojo.dto.RecordDTO;
import com.opmsys.pojo.entity.Record;
import com.opmsys.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 名称RecordServiceImpl
 * 描述
 *
 * @version 1.0
 * @author:冉启呈2021015445
 * @datatime:2024-06-19 16:55
 */
@Service
public class RecordServiceImpl implements RecordService {
    @Autowired
    private RecordMapper recordMapper;

    /**
     * 新增日记录
     * @param record
     */
    public void addRecord(Record record) {
        recordMapper.insertRecord(record);
    }

    /**
     * 删除日记录
     * @param id
     */
    public void deleteRecord(Integer id) {
        recordMapper.deleteRecord(id);
    }

    /**
     * 更新日记录
     * @param record
     */
    public void updateRecord(Record record) {
        recordMapper.updateRecord(record);
    }

    /**
     * 搜索日记录并分页
     * @param recordDTO
     * @return
     */
    public List<Record> getRecordPageWithConditions(RecordDTO recordDTO){
        List<Record> records= recordMapper.getRecordPageWithConditions(
                recordDTO.recordDate,
                recordDTO.recordStatus,
                recordDTO.dailyProduction,
                recordDTO.currentPressure,
                recordDTO.recordDetails,
                recordDTO.personNumber,
                recordDTO.pumpId,
                recordDTO.getPageSize(),
                recordDTO.getPageSize()*(recordDTO.getPage()-1)
        );
        return records;
    }

    /**
     * 搜索日记录
     * @param recordDTO
     * @return
     */
    public List<Record> getRecordListWithConditions(RecordDTO recordDTO) {
        List<Record> records= recordMapper.getRecordListWithConditions(
                recordDTO.recordDate,
                recordDTO.recordStatus,
                recordDTO.dailyProduction,
                recordDTO.currentPressure,
                recordDTO.recordDetails,
                recordDTO.personNumber,
                recordDTO.pumpId
        );
        return records;
    }

    /**
     * 核对日期是否重复
     * @param date
     * @return
     */
    public List<Record> ifdate(String date){
        return recordMapper.ifdate(date);
    }

    /**
     * 根据抽油机id查询运转记录
     * @param id
     * @return
     */
    @Override
    public List<Record> selectByPumpingId(Integer id) {
        return recordMapper.selectByPumpingId(id);
    }
}
